/*
* Copyright (c)  2017, ueboot.com
* All rights reserved.
* 2017-10-29 11:39:14
*/
package com.ueboot.weishop.service.order;

import com.ueboot.weishop.entity.order.*;
import com.ueboot.core.service.BaseService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.Date;
import java.util.List;

/**
 * Created by yangkui  on 2017-10-29 11:39:14.
 *
 * @author yangkui
 * @since 2.0 by autocode
 */
public interface OrderService extends BaseService<OrderEntity> {
    /**
     * 初始化下订单，状态为未支付
     *
     * @param order     订单
     * @param orderItem 订单明细
     */
    void saveOrder(OrderEntity order, OrderItemEntity orderItem, OrderExtensionEntity extensionEntity,
                   OrderInvoiceEntity orderInvoiceEntity,OrderReceiverEntity orderReceiverEntity);

    /**
     * 修改订单状态
     *
     * @param orderNo     订单号
     * @param orderStatus 订单状态
     * @return 更新后的订单对象
     */
    OrderEntity updateOrderStatus(String orderNo, String orderStatus);

    /**
     * 支付成功后的订单状态更新
     *
     * @param orderNo       订单号
     * @param transactionId 微信平台交易号
     * @return 更新后的订单对象
     */
    OrderEntity updateOrderStatusAndPayNotice(String orderNo, String transactionId);

    /**
     * 根据订单号查询订单
     *
     * @param orderNo 订单号
     * @return
     */
    OrderEntity findByOrderNo(String orderNo);

    Integer findGoodsCountByOrderNo(String orderNo);

    /**
     * 根据一身份标识查询订单
     * 用于当前活动针对客户限购的唯一身份标识，可以是openId,vin,mobile。具体由活动本身决定
     * @param keyForLimit
     * @return
     */
    OrderEntity findBykeyForLimit(String keyForLimit);

    /**
     * 根据用户ID查询订单
     * @param customerId 用户Id
     * @return
     */
    List<OrderEntity> findByCustomerId(Long customerId);
    /**
     * 根据用户ID分页查询订单(包括全部订单状态)
     * @param customerId 用户Id
     * @return
     */
    Page<OrderEntity> findByCustomerId(Pageable pageable, Long customerId);
    /**
     * 根据用户ID分页和和订单状态和退款申请状态查询（支付中和未支付的订单）
     * @param customerId 用户Id
     * @return
     */
    Page<OrderEntity> findByCustomerIdAndOrderStatusAndRefundStatus(Pageable pageable, Long customerId,String orderStatus,String refundStatus);

    /**
     * 根据用户ID分页和退款申请状态查询退款单
     * @param customerId 用户Id
     * @return
     */
    Page<OrderEntity> findByCustomerIdAndRefundStatusNot(Pageable pageable, Long customerId,String refundStatus);

    /**
     * 分页查询订单
     * @param pageable
     * @param params
     * @return
     */
    Page<OrderEntity> findByReq(Pageable pageable, OrderEntity params,Date startTime, Date endTime,String keyWord);

	List<OrderEntity> findByExtStatusAndOrderStatus(Integer extStatus, String orderStatus);

	String getOrderNo();

    Integer updateExtStatusByExtStatusAndOrderStatusAndCategory(Integer extStatusNow, Integer extStatusOld, String orderStatus, String category1, String category2);

	void update(OrderEntity order);
}
